package vistas.abstractModels;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import entidades.Atleta;

public class AtletaTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String[] columnNames = { "Cédula", "Nombre", "Apellido",
			"F. Nacimiento", "F. Ingreso", "Cinturon", "Direccion",
			"Teléfono A", "Teléfono B", "T. Sangre", "Beca" };
	private Object[][] data;
	private int numberOfRows;
	private int numberOfColumns;
	public static final Integer SIMPLE = 1;
	public static final Integer FULL = 2;
	public static final Integer BLACKLIST = 3;

	public AtletaTableModel(List<Atleta> rows, Integer tipo) {
		
		data = new Object[rows.size()][columnNames.length];
		numberOfRows = rows.size();
		
		
		for (int i = 0; i < rows.size(); i++) {
			if(tipo == BLACKLIST && rows.get(i).getDeuda() == 0)
				continue;
			data[i][0] = String.valueOf(rows.get(i).getId());
			data[i][1] = rows.get(i).getNombres();
			data[i][2] = rows.get(i).getApellidos();
			if (tipo == BLACKLIST || tipo == SIMPLE)
				data[i][3] = rows.get(i).getDeuda();
			else
				data[i][3] = rows.get(i).getFechaNacimiento();
			data[i][4] = rows.get(i).getFechaInscripcion();
			data[i][5] = rows.get(i).getCinturon();
			data[i][6] = rows.get(i).getDireccion();
			data[i][7] = rows.get(i).getTelefonoA();
			data[i][8] = rows.get(i).getTelefonoB();
			data[i][9] = rows.get(i).getTipoSangre();
			if (rows.get(i).isBecado())
				data[i][10] = "Sí";
			else
				data[i][10] = "No";
		}
	
			
		
		if (tipo == SIMPLE || tipo == BLACKLIST){
			numberOfColumns = 4;
			columnNames[3] = "Deuda (Meses)";
		}
		else{
			numberOfColumns = columnNames.length;
		}
	}

	@Override
	public int getRowCount() {
		return numberOfRows;
	}

	@Override
	public int getColumnCount() {
		return numberOfColumns;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return data[rowIndex][columnIndex];
	}

	public String getColumnName(int index) {
		return columnNames[index];

	}
}
